package com.mxpio.erp.plm.controller;

import com.mxpio.erp.common.enums.CommonEnums;
import com.mxpio.erp.common.plm.entity.ProjectTask;
import com.mxpio.erp.common.plm.entity.ProjectTaskCompleteDeliverableDraft;
import com.mxpio.erp.common.plm.service.ProjectTaskCompleteDeliverableDraftService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "ProjectTaskCompleteDeliverableDraftController", description = "项目任务完工-任务交付物草稿表")
@RestController
@RequestMapping("/erp/plm/pro/task/complete/DeliverableDraft")
public class ProjectTaskCompleteDeliverableDraftController {

    @Autowired
    private ProjectTaskCompleteDeliverableDraftService draftService;
    @GetMapping("list/{taskLogId}")
    @Operation(summary = "根据任务编码获取任务交付物列表模版", description = "根据任务编码获取任务交付物列表模版", method = "GET")
    public Result<List<ProjectTaskCompleteDeliverableDraft>> getByProId(@PathVariable(name = "taskLogId", required = true) String taskLogId) {
        Criteria criteria = Criteria.create();
        Criteria criteria1 = criteria.addCriterion("taskLogId", Operator.EQ, taskLogId);
        List<ProjectTaskCompleteDeliverableDraft> tasks = draftService.list(ProjectTaskCompleteDeliverableDraft.class, criteria1);
//        List<ProjectTaskCompleteDeliverableDraft> deliverableDrafts = new ArrayList<>();
//        for (ProjectTaskCompleteDeliverableDraft task : tasks){
//            if (task.getIsAuditEnd()==null ||task.getIsAuditEnd().equals(CommonEnums.YesNo.NO.getCode())){
//                deliverableDrafts.add(task);
//            }
//        }
        return Result.OK(tasks);
    }
}
